package com.violet.utils;

import com.violet.domain.exceptions.DTOVerifyException;
import org.springframework.stereotype.Component;

public class CodeUtils {

    // 生成 6 位随机数
    public static String generateCode() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 6; i++) {
            sb.append((int) (Math.random() * 10));
        }
        return sb.toString();
    }

    // 校验验证码
    public static void checkCode(String phone, String code) {
        if (!"123456".equals(code)) throw new DTOVerifyException("验证码错误", "code");
    }

}
